<script type="text/javascript"><!--//--><![CDATA[//><!--

    var grid_reload = function() {
        $('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
    };
    
    $(document).ready(function() {
       // Setup Datagrid
		$('#datagrid').datagrid({  
			url:gs_path+'/'+controller+'/getdata', 
			queryParams: $('#fm_search').serializeObject(),
			height:340,
			pagination:true,
			//singleSelect:true,
			columns:[[
				{ field : 'ck', checkbox:true, width: 40, align: 'center' },
				{ field : 'kode_kontrak', title : 'Kode Kontrak', width : 170, sortable:true },
				{ field : 'kode_customer', title : 'Kode Client', width : 120, sortable:true },
				{ field : 'no_invoice', title : 'No Invoice', width : 170, sortable:true },
				{ field : 'periode_tagihan', title : 'Periode Tagihan', width : 100, sortable:true },
				{ field : 'tanggal_invoice', title : 'Tanggal Invoice', width : 100, sortable:true },
				{ field : 'due_date', title : 'Due Date Invoice', width : 100, sortable:true },
				{ field : 'status', title : 'Status', width : 100, sortable:true },
				//{ field : 'total', title : 'Total Bayar', width : 100, sortable:true },	
				{ field : 'tanggal_bayar', title : 'Tanggal Bayar', width : 100, sortable:true },
				{ field : 'keterangan', title : 'Keterangan', width : 150, sortable:true }
				]]
		});

		  // Setup Form
		$('#form_master').setupForm([
			{ name: 'bulan', type: 'text', size: 'short'},
			{ name: 'tahun', type: 'text', size: 'short'},
			{ name: 'tanggal', type: 'date', size: 'short'},
		]);

		// Create Dialog
		$('#dialog_container').dialog({
			closed:true,
			modal:true,
			title: 'Pilihan Berdasarkan Tanggal',
			width:400,
			height:200,
			buttons:[{
				text:'Print',
				iconCls:'print',
				handler:function(){
					$('#form_master').submitForm('/'+controller+'/ajax_post', { onComplete : function(){ $('#dialog_container').dialog('close'); $('#datagrid').datagrid('reload'); }} );
				}
			},{
				text:'Close',
				iconCls:'icon-cancel',
				handler:function(){
					$('#dialog_container').dialog('close');
				}
			}]
		});
        
        // Set Action Button
        var buttons = [ 
                       // ----- >> Edit Button
					     { label: 'Print Custom', icon: 'edit', onclick: function() {
					         var oSel = $('#datagrid').datagrid('getSelected');
					         if (oSel == null) {
					             $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
					         } else {
								 loadPage(gs_path+'/'+controller+'/custom/?kode_kontrak='+urlencode(oSel.kode_kontrak)+'&& id_invoice='+urlencode(oSel.id_invoice));
					         } 
					     }},
					   { label: 'Print to Excel', icon: 'print', onclick: function() {
							var oSel = $('#datagrid').datagrid('getSelected');
					        if (oSel == null) {
					            $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
					        } else {
								window.location = gs_path + '/isp_print_excel/invoice_excel_satuan/?no_invoice='+urlencode(oSel.no_invoice);
							}
					    }},
					   { label: 'Print PDF', icon: 'print', onclick: function() {
							var oSel = $('#datagrid').datagrid('getSelected');
							var no_id = oSel['no_id'];
							var no_invoice = oSel['no_invoice'];
							//alert(no_id);
					        if (oSel == null) {
					            $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
					        } else {
								window.open(gs_path+'/'+controller+'/cetak/?no_invoice='+no_invoice+'&& no_id='+no_id+'&& kode_kontrak='+urlencode(oSel.kode_kontrak), 'myWin', 'height=500,width=700,status=yes,toolbar=no,menubar=yes,location=no,scrollbars=yes');
							}
					    }},
					    { label: 'Print PDF non TTD', icon: 'print', onclick: function() {
							var oSel = $('#datagrid').datagrid('getSelected');
					        var no_id = oSel['no_id'];
							var no_invoice = oSel['no_invoice'];
					        if (oSel == null) {
					            $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
					        } else {
								window.open(gs_path+'/'+controller+'/cetak_ext/?no_invoice='+no_invoice+'&& no_id='+no_id+'&& kode_kontrak='+urlencode(oSel.kode_kontrak), 'myWin', 'height=500,width=700,status=yes,toolbar=no,menubar=yes,location=no,scrollbars=yes');
							}
					    }},
					    { label: 'Print Semua', icon: 'print', onclick: function() {
					    		/*var bulan = $('#bulan').val();
								var tahun = $('#tahun').val(); 
								var tanggal = bulan+'-'+tahun;*/
								window.location = gs_path + '/isp_print_excel/invoice/'/*?tanggal=+tanggal*/;
					     	
					     }},

						// ----- >> Download Button
						
						// ----- >> SP Button
					    ];
        setAction(buttons);
		
		
		$('#fm_search').focusFirst();
    });
//--><!]]></script>

    
<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
        	<!-- <tr>
				<td class="label" style="width:70px">Periode Tagihan</td>
				<td ><select id="bulan" name="bulan">
					<option value="Januari">Januari</option>
					<option value="Februari">Februari</option>
					<option value="Maret">Maret</option>
					<option value="April">April</option>
					<option value="Mei">Mei</option>
					<option value="Juni">Juni</option>
					<option value="Juli">Juli</option>
					<option value="Agustus">Agustus</option>
					<option value="September">September</option>
					<option value="Oktober">Oktober</option>
					<option value="November">November</option>
					<option value="Desember">Desember</option>
				</select>
				<?php
				$now = date('Y');
				$pastYear = $now - 10; 
				echo "<select id='tahun' name='tahun' >";
				for ($a=$pastYear;$a<=$now;$a++)
				{
					echo"<option value='".$a."''>".$a."</option>";	
				}
				echo"</select>";
				?>
			</td>
		</tr>  -->
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-blank-file" onclick="$('#fm_search').resetForm(); return false;">Reset</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>

<div id="dialog_container" style="padding:5px;width:600px;height:250px;">
	<form action="" method="post">
		<table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
			  
		
	</table>
</form> 
</div>